package czy.demo.config.shiro;

import org.apache.shiro.authc.AuthenticationException;
import org.apache.shiro.authc.AuthenticationInfo;
import org.apache.shiro.authc.AuthenticationListener;
import org.apache.shiro.authc.AuthenticationToken;
import org.apache.shiro.subject.PrincipalCollection;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Component;

/* 默认认证监听器，由Authenticator调用 */
@Component
public class DefaultAuthenticationListener implements AuthenticationListener {

    private static final Logger logger = LoggerFactory.getLogger(DefaultAuthenticationListener.class);

    @Override
    public void onSuccess(AuthenticationToken token, AuthenticationInfo info) {
        logger.debug("用户"+info.getPrincipals().getPrimaryPrincipal()+"认证成功");
    }

    @Override
    public void onFailure(AuthenticationToken token, AuthenticationException ae) {
        logger.error("用户"+token.getPrincipal()+"认证失败",ae);
    }

    @Override
    public void onLogout(PrincipalCollection principals) {
        logger.debug("用户"+principals.getPrimaryPrincipal()+"登出");
    }
}
